/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import com.google.inject.Inject;
import com.ibm.staf.STAFException;
import com.ibm.staf.STAFHandle;
import com.ibm.staf.STAFResult;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author think
 */
public class ServerUtil {
    ConfigManager configManager;

    @Inject
    public ServerUtil(ConfigManager config){
        configManager = config;
    }


    public boolean createServerSideProjectArchive() {
        try {
            STAFHandle handle = new STAFHandle("SU");
            File archive = new File(configManager.getProjectArchiveName());
            if (archive.exists()) {
                archive.delete();
            }
            handle = new STAFHandle(configManager.getZipHandleName());
            STAFResult result = handle.submit2(configManager.getServerHostName(), "zip", "add zipfile " + "\"" + configManager.getProjectArchiveName().replace("\\", "/") +
                    "\" directory \"" + configManager.getProjectPath().replace("\\", "/") + "\" relativeto \"" + configManager.getProjectPath().replace("\\", "/") + "\" recurse");
            handle.unRegister();
            if (result.rc == 0) {
                return true;
            } else {
                System.out.println(result.result);
            }
        } catch (STAFException ex) {
            Logger.getLogger(VMMachine.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;

    }
}
